package com.qiaofang.applet.service.property.service.impl;

import com.qiaofang.applet.common.base.MongoBaseService;
import com.qiaofang.applet.service.other.service.dto.CountSynDataDto;
import com.qiaofang.applet.service.property.domain.DataProcessingErrorLog;
import com.qiaofang.applet.service.property.domain.SyncDataErrorLog;
import com.qiaofang.applet.service.property.repository.DataProcessingErrorLogRepository;
import com.qiaofang.applet.service.property.service.DataProcessingErrorLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Service;

@Service
public class DataProcessingErrorLogServiceImpl extends MongoBaseService<DataProcessingErrorLog, String> implements DataProcessingErrorLogService {

    private final DataProcessingErrorLogRepository repository;

    @Autowired
    private MongoTemplate mongoTemplate;

    public DataProcessingErrorLogServiceImpl(DataProcessingErrorLogRepository repository) {
        super(repository);
        this.repository=repository;
    }

    @Override
    public long resolveDataErrorCount(CountSynDataDto countSynDataDto) {
        Query query = new Query();
        Criteria criteria = Criteria.where("corporationCode").is(countSynDataDto.getCorporationCode());
        criteria.and("companyUuid").is(countSynDataDto.getCompanyUuid());
        criteria.and("cityCode").is(countSynDataDto.getCityCode());
        criteria.and("updateTime").gte(countSynDataDto.getUpdateTime());
        query.addCriteria(criteria);
        return mongoTemplate.count(query, DataProcessingErrorLog.class);

    }
}
